<?php 

/**
*Form Builder & Admin Generator

*@author marcio <opi14@op.pl>, <polishvodka7@gmail.com>
*@copyright Copyright (c) 2011, marcio
*@version 1.6.5
*/

require_once('abstract/Panel.php');

class Table_Standard extends Volta_View_Panel
{

	public function render()
	{
	
		$panel .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'">
				   <table align="center" style="border:3px solid #000000;"><tr><td>
		           <table align="right"><tr>';
	
		if($this -> get('new_action'))
		{
			$panel .= '<td><a href="?action=create_'.$this -> get('table').'">
					   <input type="button" value="Nowy">
					   </a></td>';
		}
		
		$panel .= '<td>
		<input type="submit" name="del_checked" value="Usun zaznaczone">
		</td></tr></table></td></tr><tr><td>';
		$panel .= '<table align="center" cellpadding="3" cellspacing="0">';
		$panel .= '<tr>';

		foreach($this -> get_columns('cols') as $key => $column)
		{	
			if(in_array($column, $this -> get_columns('allowed')))
			{
				$sort = ($_GET['sort'] == $column) ? '|'.$column.'|' : $column;
				$panel .= '<td align="center" style="padding:2px;background-color:#8B0000;font-weight:bold;"><a href="?sort='.$column.'" style="text-decoration:none;color:#000000;">'.$sort.'</a></td>';
			}
		}
		
		$panel .= '<td align="center"style="background-color:#8B0000;font-weight:bold;">Akcje</td>';
		$panel .= '</tr>';
		
		$i = 0;
		
		foreach($this -> get_records() as $record)
		{
			
			if($i % 2 == 0)
				$color = '#778899';
			else
				$color = '#C0C0C0';
		
			if(sizeof($this -> get('relation')) > 0)
				$js = 'onclick="window.location.href=\'?relationship='.$this -> get('table').'&'.$this -> get('where_rel').'='.$record[$this -> get('where_rel')].'\'"';
			
			$panel .= '<tr style="background-color:'.$color.';">';
			
			foreach($record as $column => $data)
				if(in_array($column, $this -> get_columns('allowed')))
					$panel .= '<td '.$js.'>'.$data.'</td>';
				
			$panel .= '<td>';
				
			foreach($this -> get('actions') as $action => $description)
			{
				if($action == 'delete')
					$panel .= '<a href="#" onClick="if(confirm(\'Czy na pewno chcesz usunac\')) {window.location.href=\'?action='.$action.'_'.$this -> get('table').'&'.$this -> get('where').'='.$record[$this -> get('where')].'\'}">';
				else
					$panel .= '<a href="?action='.$action.'_'.$this -> get('table').'&'.$this -> get('where').'='.$record[$this -> get('where')].'" '.$confirm.'>';

				if(sizeof($description) > 0)
					$panel .= '<img src="'.$description[1].'" alt="'.$description[0].'">';
				else
					$panel .= '<input type="button" value="'.$description.'">';
						   
				$panel .= '</a>';	
			}
			
			$panel .= '<input type="checkbox" value="'.$record['id'].'" name="del[]">';
			$panel .= '</td></tr>';
			
			$i++;
		}
		
		$panel .= '</table></td></tr></table></form>';
		
		$msg = $this -> get_message();
		if(!empty($msg))
			$panel .= '<div align="center" style="padding:5px;margin:5px;background-color:#C0C0C0;border:1px solid #ff0033;"><b>'.$msg.'</b></div>';

		return $panel;
	}
	
}
?>